home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / PCCDEMO.ZIP / COMP1.EXE / SB.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-20  |  4KB  |  205 lines

  1. {** SB.PAS - By Steven Arnold **}
  2. uses crt;
  3.  
  4. const
  5.   maxsize = 65000;
  6.  
  7. var
  8.   CTVDriver : pointer;
  9.   CTVSize : word;
  10.  
  11.  
  12. procedure LoadCTV(filename : string);
  13.  
  14. { Loads the CT-VOICE driver into memory, pointed to by "CTVDriver" }
  15.  
  16. var
  17.   f : file;
  18.  
  19. begin
  20.   assign(f, filename);
  21.   {$i-}
  22.   reset(f, 1);
  23.   {$i+}
  24.   if ioresult <> 0 then
  25.   begin
  26.     writeln('Error loading ', filename);
  27.     halt;
  28.   end;
  29.   CTVSize := filesize(f);
  30.   getmem(CTVDriver, CTVSize);           { Allocate the memory required }
  31.   blockread(f, CTVDriver^, CTVSize);    { Read the driver in to this memory }
  32.   close(f);
  33. end;
  34.  
  35. Function CTVVersion:Word; assembler;
  36.  
  37. { Returns the version number of the loaded CT-Voice Driver }
  38.  
  39. asm
  40.   mov bx, 0
  41.   call CTVDriver
  42. end;            { Return is via AX }
  43.  
  44. procedure SetBaseAddr(address : word); assembler;
  45.  
  46. { Sets the base address of the sound card }
  47.  
  48. asm
  49.   mov bx, 1
  50.   mov ax, address
  51.   call CTVDriver
  52. end;
  53.  
  54. procedure SetInterrupt(int : word); assembler;
  55.  
  56. { Sets the interrupt number of the sound card }
  57.  
  58. asm
  59.   mov bx, 2
  60.   mov ax, int
  61.   call CTVDriver
  62. end;
  63.  
  64. function InitSB:boolean; assembler;
  65.  
  66. { Initialises the sound card }
  67.  
  68. asm
  69.   mov bx, 3
  70.   call CTVDriver
  71.   cmp ax, 0
  72.   jne @false
  73.   mov ax, word(TRUE)
  74.   jmp @done
  75. @false:
  76.   mov ax, word(FALSE)
  77. @done:
  78. end;            { Return is via AX }
  79.  
  80. procedure Speaker(state : boolean); assembler;
  81.  
  82. {Turns on/off speaker ; If "state" is TRUE, the speaker is turned on }
  83.  
  84. asm
  85.   mov bx, 4
  86.   mov ax, word(state)
  87.   call CTVDriver
  88. end;
  89.  
  90. procedure PlayVoice(voice : pointer); assembler;
  91.  
  92. { Plays the voice, pointed to by "voice" }
  93.  
  94. asm
  95.   mov bx, 6
  96.   les di, voice
  97.   call CTVDriver
  98. end;
  99.  
  100. procedure CancelPlay; assembler;
  101.  
  102. { Cancels playing of a voice }
  103.  
  104. asm
  105.   mov bx, 8
  106.   call CTVDriver
  107. end;
  108.  
  109. procedure DoneSB; assembler;
  110.  
  111. { Un-initialises sound card }
  112.  
  113. asm
  114.   mov bx, 9
  115.   call CTVDriver
  116. end;
  117.  
  118. procedure StartSB;
  119. var
  120.   version : word;
  121. begin
  122.   LoadCTV('CT-VOICE.DRV');       {Specify the full path to CT-VOICE here
  123.                                   if it is not in the current directory}
  124.  
  125.   SetBaseAddr($220);        {Change these values to suit your configuration}
  126.   SetInterrupt(7);
  127.  
  128.   if not InitSB then
  129.   begin
  130.     writeln('Trouble initialising sound card.');
  131.     halt;
  132.   end;
  133.  
  134.   version := CTVVersion;
  135.   writeln('CT-Voice version ',hi(version), '.', lo(version));
  136.   Speaker(TRUE);
  137. end;
  138.  
  139. procedure FinishSB;
  140. begin
  141.   Speaker(FALSE);
  142.   DoneSB;
  143.   freemem(CTVDriver, CTVSize);
  144. end;
  145.  
  146. procedure LoadVoice(fn : string; buf : pointer; bufsize : word);
  147.  
  148. { Loads a voice file from disk, into memory pointed to by "buf" }
  149.  
  150. var
  151.   f : file;
  152.   result : word;
  153.  
  154. begin
  155.   assign(f, fn);
  156.   {$i-}
  157.   reset(f, 1);
  158.   if ioresult <> 0 then
  159.   begin
  160.     writeln('Error loading voice file');
  161.     halt;
  162.   end;
  163.  
  164.   seek(f, 26);     {Skip text in VOC-Header}
  165.   if ioresult <> 0 then
  166.   begin
  167.     writeln('Error loading voice file');
  168.     halt;
  169.   end;
  170.   {$i+}
  171.  
  172.   blockread(f, buf^, bufsize, result);
  173.  
  174.   close(f);
  175. end;
  176.  
  177. var
  178.   vocfn : string;
  179.   voice : pointer;
  180.   reply : char;
  181.  
  182. begin
  183.   StartSB;
  184.  
  185.   write('Enter filename : ');
  186.   readln(vocfn);
  187.   if pos('.', vocfn)=0 then vocfn := vocfn+'.VOC';
  188.  
  189.   getmem(voice, maxsize);
  190.   LoadVoice(vocfn, voice, maxsize);
  191.  
  192.   writeln('Press any key to play "', vocfn, '"  or "Q" to quit');
  193.   writeln;
  194.  
  195.   reply := readkey;
  196.   while (upcase(reply) <> 'Q') do
  197.   begin
  198.     CancelPlay;
  199.     PlayVoice(voice);
  200.     reply := readkey;
  201.   end;
  202.  
  203.   freemem(voice, maxsize);
  204.   FinishSB;
  205. end.